package com.shinbada.modules.sys.web.app;

import com.shinbada.common.json.AjaxJson;
import com.shinbada.common.tree.TreeUtil;
import com.shinbada.core.web.BaseController;
import com.shinbada.modules.sys.entity.Office;
import com.shinbada.modules.sys.service.OfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author initcap
 * @date 2020/10/6 12:50
 */
@RestController
@RequestMapping("/app/sys/office")
public class AppOfficeController extends BaseController {

    @Autowired
    private OfficeService officeService;

    /**
     * 获取机构JSON数据。
     *
     * @param extId 排除的ID
     * @param type  类型（1：公司；2：部门/小组/其它）
     * @return
     */
    @GetMapping("treeData")
    public AjaxJson treeData(@RequestParam(required = false) String extId, @RequestParam(required = false) String type,
                             @RequestParam(required = false) Boolean isAll) {
        List<Office> list = officeService.findList(isAll);
        return AjaxJson.success().put("treeData", TreeUtil.buildLevelTreeSort(list));
    }

}
